//
//  NSString+EL.m
//  jobClient
//
//  Created by 一览ios on 2017/7/10.
//  Copyright © 2017年 YL1001. All rights reserved.
//

#import "NSString+EL.h"

@implementation NSString (EL)

// 获取大写拼音
+ (NSString *)stringToPinYin:(NSString *)aString
{
    if (StringIsEmpty(aString)) return nil;
    //转成了可变字符串
    NSMutableString *str = [NSMutableString stringWithString:aString];
    //先转换为带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
    //再转换为不带声调的拼音
    CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
    //转化为大写拼音
    NSString *pinYin = [str capitalizedString];
    
    return pinYin;
}


// 获取拼音首字母(传入汉字字符串, 返回大写拼音首字母)
+ (NSString *)initialsWithString:(NSString *)aString
{
    if (StringIsEmpty(aString)) return nil;
    
    //转化为大写拼音
    NSString *pinYin = [self stringToPinYin:aString];
    //获取并返回首字母
    return [pinYin substringToIndex:1];
}

@end
